import { craeteEffect, effectTypes } from './helper'

/**
 * cancel 用于取消一个或者多个任务, 不传就是当前任务
 * @export
 * @param {*} tasks
 */
export function cancel(...tasks) {
    return craeteEffect(effectTypes.CANCEL, { tasks })
}

/**
 * 处理 fork effect 
 * @export
 * @param {*} env
 * @param {*} effect
 * @param {*} next
 */
export function runCancelEffect(env, effect, next) {
    const { payload: { tasks } } = effect
    tasks.forEach(t => t.cancel(t))
    next()
}